package com.heu.blood.charge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heu.blood.charge.entity.ChargeItemApplicationEntity;
import org.apache.logging.log4j.util.Strings;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.Query;

import com.heu.blood.charge.dao.ChargeItemDao;
import com.heu.blood.charge.entity.ChargeItemEntity;
import com.heu.blood.charge.service.ChargeItemService;


@Service
public class ChargeItemServiceImpl extends ServiceImpl<ChargeItemDao, ChargeItemEntity> implements ChargeItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        ChargeItemEntity entity = new ChargeItemEntity();

        if(Strings.isNotBlank((String) params.get("patientId")))
            entity.setPatientId((String) params.get("patientId"));
        if(Strings.isNotBlank((String) params.get("chargeId")))
            entity.setChargeId((String) params.get("chargeId"));
        if(Strings.isNotBlank((String) params.get("chargeType")))
            entity.setChargeId((String) params.get("chargeType"));
        if(Strings.isNotBlank((String) params.get("chargeProject")))
            entity.setChargeId((String) params.get("chargeProject"));
        if(Strings.isNotBlank((String) params.get("operator")))
            entity.setOperator((String) params.get("operator"));
        if(Strings.isNotBlank((String) params.get("isReturn")))
            entity.setIsReturn(Integer.valueOf((String) params.get("isReturn")));



        //添加时间范围条件
        String startTime = null;
        String endTime = null;
        if(Strings.isNotBlank((String)params.get("startTime")))
            startTime = (String)params.get("startTime");
        if(Strings.isNotBlank((String)params.get("endTime")))
            endTime = (String)params.get("endTime");



        LambdaQueryWrapper<ChargeItemEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Strings.isNotBlank(entity.getChargeId()),ChargeItemEntity::getChargeId,entity.getChargeId())
                .eq(Strings.isNotBlank(entity.getPatientId()),ChargeItemEntity::getPatientId,entity.getPatientId())
                .eq(Strings.isNotBlank(entity.getChargeType()),ChargeItemEntity::getChargeType,entity.getChargeType())
                .eq(Strings.isNotBlank(entity.getChargeProject()),ChargeItemEntity::getChargeProject,entity.getChargeProject())
                .eq(Strings.isNotBlank(entity.getOperator()),ChargeItemEntity::getOperator,entity.getOperator())
                .eq(entity.getIsReturn() != null,ChargeItemEntity::getIsReturn,entity.getIsReturn())
                .ge(Strings.isNotBlank(startTime),ChargeItemEntity::getChargeTime,startTime)
                .le(Strings.isNotBlank(endTime),ChargeItemEntity::getChargeTime,endTime)
                .eq(ChargeItemEntity::getIfShow,1);






        IPage<ChargeItemEntity> page = this.page(
                new Query<ChargeItemEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}